/*
 * 项   目：code-generator
 * 作   者：LuoYiMin
 * 邮   箱：1725990142@qq.com
 * 创建时间：2018/12/28 9:07
 */
package com.roin.util.code.generator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class DefaultConfig {
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultConfig.class);

    private static Properties config;
    public static String FREEMARKER_VARIABLE_NAME="config";
    static {
        init();
    }

    private static void init(){
        if (config!=null)
            return;
        LOGGER.debug("开始加载配置文件roin/config.properties");
        config = new Properties();
        InputStream in = null;
        try {
        	in = DefaultConfig.class.getClassLoader().getResourceAsStream("roin/config.properties");
        	config.load(in);
        } catch (FileNotFoundException e) {
            LOGGER.error("config.properties文件未找到");
        } catch (IOException e) {
            LOGGER.error("加载config.properties文件出现IOException");
        } finally {
            try {
                if (null != in) {
                    in.close();
                }
            } catch (IOException e) {
                LOGGER.error("config.properties文件流关闭出现异常");
            }
        }
        LOGGER.info("加载properties文件内容完成...........");
        LOGGER.info("properties文件内容：" + config);
    }

    public static String getValue(String key){
        return config.getProperty(key);
    }
    public static String getValue(String key,String defaultValue){
        return config.getProperty(key,defaultValue);
    }

    public static String getHtmlBaseUrl(){
        return config.getProperty("html.baseUrl");
    }

    public static boolean isHtmlShowCheckBox() {
        return Boolean.valueOf(config.getProperty("html.showCheckBox","true"));
    }

    public static String getControllerTemplateName(){
        return config.getProperty("controller.templateName");
    }
    public static String getServiceTemplateName(){
        return config.getProperty("service.templateName");
    }
    public static String getServiceImplTemplateName(){
        return config.getProperty("service.implTemplateName");
    }
    public static String getHtmlTemplateName(){
        return config.getProperty("html.templateName");
    }
    public static String getHtmlAddTemplateName(){
        return config.getProperty("html.addTemplateName");
    }
}
